﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NewFormatProject.Infrastructure.Atrributes;
using NewFormatProject.Infrastructure.Dto.Requests.Objects;
using NewFormatProject.Server.Interfaces;
using System.Threading.Tasks;

namespace NewFormatProject.Api.Admin.Controllers
{
    [Authorize]
    [CheckLogin]
    public class JobController : BaseController
    {
        private readonly IJobServer _jobServer;
        public JobController(IJobServer jobServer)
        {
            _jobServer = jobServer;
        }
        /// <summary>
        /// 获取职位详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Detail(int id)
        {
            return Ok( await _jobServer.Detail(id));
        }

        /// <summary>
        /// 获取部门下的职位
        /// </summary>
        /// <param name="depId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetJobByDepartmentId(int depId)
        {
            return Ok(await _jobServer.GetJobByDepartmentId(depId));
        }

        /// <summary>
        /// 以分页的形式获取职位列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Pagination(int page, int limit, string key)
        {
            return Ok(await _jobServer.Pagination(page, limit, key));
        }
        /// <summary>
        /// 添加职位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("添加职位")]
        public async Task<IActionResult> Add(RequestJobsDto dto)
        {
            return Ok(await _jobServer.Add(dto));
        }
        /// <summary>
        /// 修改职位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("修改职位")]
        public async Task<IActionResult> Update(RequestJobsDto dto)
        {
            return Ok(await _jobServer.Update(dto));
        }
        /// <summary>
        /// 删除职位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("删除职位")]
        public async Task<IActionResult> Delete(RequestJobsDto dto)
        {
            return Ok(await _jobServer.Delete(dto));
        }
    }
}
